home *** CD-ROM | disk | FTP | other *** search
/ Champak 130 / Vol 130.iso / games / tom.swf / scripts / classes / game / Game.as next >
Encoding:
Text File  |  2011-04-12  |  6.4 KB  |  268 lines

  1. package classes.game
  2. {
  3.    import classes.Main;
  4.    import flash.display.*;
  5.    import flash.events.*;
  6.    import flash.media.*;
  7.    import flash.utils.Timer;
  8.    import libs.kjc.*;
  9.    
  10.    [Embed(source="/_assets/assets.swf", symbol="classes.game.Game")]
  11.    public class Game extends MovieClip
  12.    {
  13.       
  14.       internal static var reStart:Function;
  15.        
  16.       
  17.       public var ScoreBox:ScoreBox;
  18.       
  19.       public var MissionBar:MissionBar;
  20.       
  21.       private var lv:int;
  22.       
  23.       private var score:int;
  24.       
  25.       private var cNum:int;
  26.       
  27.       private var addNum:int;
  28.       
  29.       private var spd:Number;
  30.       
  31.       private var tTimer:Timer;
  32.       
  33.       public var Tom:Tom;
  34.       
  35.       private var playOn:Boolean;
  36.       
  37.       private var cTim:int;
  38.       
  39.       private var addTim:int;
  40.       
  41.       private var deleyR:int;
  42.       
  43.       public var bg:MovieClip;
  44.       
  45.       private var timer:Timer;
  46.       
  47.       private var mTim:int;
  48.       
  49.       private var tNum:int;
  50.       
  51.       private var bonusTim:int;
  52.       
  53.       private var spdA:Array;
  54.       
  55.       private var life:int;
  56.       
  57.       private var deley:int;
  58.       
  59.       public function Game()
  60.       {
  61.          super();
  62.          playOn = false;
  63.          this.bg.gotoAndStop(1);
  64.          reStart = gameReady;
  65.          lv = 0;
  66.          score = 0;
  67.          life = 3;
  68.          tNum = 1;
  69.          addNum = 1;
  70.          mTim = 30;
  71.          addTim = 3;
  72.          bonusTim = 2;
  73.          spdA = new Array(1,1,1.2,1.2,1.5,2);
  74.          deley = 3000;
  75.          deleyR = 1500;
  76.          this.ScoreBox.setScore(score);
  77.          gameReady();
  78.          tTimer = new Timer(1000);
  79.          tTimer.addEventListener(TimerEvent.TIMER,addTimFn);
  80.          timer = new Timer(1500,1);
  81.          timer.addEventListener(TimerEvent.TIMER,playGame);
  82.          Panel.tom = this.Tom;
  83.       }
  84.       
  85.       private function gameStart(param1:MovieClip = null) : void
  86.       {
  87.          var _loc2_:int = 0;
  88.          if(param1 != null)
  89.          {
  90.             KJC_general.remove(param1);
  91.          }
  92.          mTim += addTim;
  93.          if(mTim >= 34)
  94.          {
  95.             addTim = -addTim;
  96.          }
  97.          tNum += addNum;
  98.          if(tNum > 8)
  99.          {
  100.             tNum = 8;
  101.          }
  102.          if(lv >= spdA.length)
  103.          {
  104.             _loc2_ = int(spdA.length - 1);
  105.          }
  106.          else
  107.          {
  108.             _loc2_ = lv;
  109.          }
  110.          spd = spdA[_loc2_];
  111.          this.bg.gotoAndStop(1 + lv % 3);
  112.          ++lv;
  113.          this.ScoreBox.setLv(lv);
  114.          gameReStart();
  115.       }
  116.       
  117.       public function keyFn(param1:String) : void
  118.       {
  119.          if(playOn == false)
  120.          {
  121.             return;
  122.          }
  123.          this.Tom.actionTom(param1);
  124.       }
  125.       
  126.       internal function missionSucces(param1:int) : void
  127.       {
  128.          var _loc3_:Photo = null;
  129.          if(playOn == false)
  130.          {
  131.             return;
  132.          }
  133.          Main.playSound(1);
  134.          cTim -= bonusTim;
  135.          var _loc2_:Boolean = this.MissionBar.clearMission(param1);
  136.          if(_loc2_ == true)
  137.          {
  138.             ++cNum;
  139.             Main.playSound(2);
  140.             setScore(1500);
  141.             _loc3_ = new Photo();
  142.             this.addChild(_loc3_);
  143.             _loc3_.y = 180;
  144.             _loc3_.x = this.Tom.x;
  145.             if(cNum == tNum)
  146.             {
  147.                levelUpFn();
  148.             }
  149.          }
  150.          else
  151.          {
  152.             setScore(300);
  153.          }
  154.       }
  155.       
  156.       private function gameReStart(param1:MovieClip = null) : void
  157.       {
  158.          this.Tom.reSetTom();
  159.          cNum = 0;
  160.          cTim = 0;
  161.          this.MissionBar.setMissionBar(tNum);
  162.          this.ScoreBox.setTim(cTim,mTim);
  163.          playOn = true;
  164.          tTimer.reset();
  165.          tTimer.start();
  166.          timer.reset();
  167.          timer.start();
  168.       }
  169.       
  170.       private function gamePause() : void
  171.       {
  172.          playOn = false;
  173.          tTimer.stop();
  174.          timer.stop();
  175.       }
  176.       
  177.       private function playGame(param1:Event) : void
  178.       {
  179.          if(playOn == false)
  180.          {
  181.             return;
  182.          }
  183.          var _loc2_:Panel = new Panel();
  184.          this.addChildAt(_loc2_,3);
  185.          var _loc3_:int = KJC_general.Random(4);
  186.          _loc2_.x = 100 + _loc3_ * 75;
  187.          _loc2_.y = 395;
  188.          var _loc4_:Number = (2 - _loc3_) * 5;
  189.          _loc2_.setPanel(spd,_loc4_);
  190.          timer.removeEventListener(TimerEvent.TIMER,playGame);
  191.          var _loc5_:int = KJC_general.Random(deleyR) + deley;
  192.          timer = new Timer(_loc5_,1);
  193.          timer.addEventListener(TimerEvent.TIMER,playGame);
  194.          timer.start();
  195.       }
  196.       
  197.       internal function setScore(param1:int) : void
  198.       {
  199.          if(playOn == false)
  200.          {
  201.             return;
  202.          }
  203.          score += param1;
  204.          if(score < 0)
  205.          {
  206.             score = 0;
  207.          }
  208.          this.ScoreBox.setScore(score);
  209.       }
  210.       
  211.       internal function gameReady(param1:MovieClip = null, param2:Boolean = true) : void
  212.       {
  213.          if(param1 != null)
  214.          {
  215.             KJC_general.remove(param1);
  216.          }
  217.          Main.setStageFocus();
  218.          var _loc3_:StartMc = new StartMc();
  219.          this.addChild(_loc3_);
  220.          if(param2 == true)
  221.          {
  222.             KJC_enterframe.moveToFrame(_loc3_,_loc3_.totalFrames,gameStart);
  223.          }
  224.          else
  225.          {
  226.             KJC_enterframe.moveToFrame(_loc3_,_loc3_.totalFrames,gameReStart);
  227.          }
  228.       }
  229.       
  230.       private function addTimFn(param1:Event) : void
  231.       {
  232.          ++cTim;
  233.          this.ScoreBox.setTim(cTim,mTim);
  234.          if(cTim >= mTim)
  235.          {
  236.             gameOver();
  237.          }
  238.       }
  239.       
  240.       private function levelUpFn() : void
  241.       {
  242.          gamePause();
  243.          setScore(5000);
  244.          var _loc1_:LevelUp = new LevelUp();
  245.          this.addChild(_loc1_);
  246.       }
  247.       
  248.       internal function gameOver() : void
  249.       {
  250.          var _loc1_:GameOver = null;
  251.          gamePause();
  252.          --life;
  253.          this.ScoreBox.setLife(life);
  254.          this.Tom.actionTom("FAIL");
  255.          if(life == 0)
  256.          {
  257.             SoundMixer.stopAll();
  258.             _loc1_ = new GameOver(score);
  259.             this.addChild(_loc1_);
  260.          }
  261.          else
  262.          {
  263.             gameReady(null,false);
  264.          }
  265.       }
  266.    }
  267. }
  268.